#include <cstdlib>
#include <memory>

#include "common/log/log.h"

#include "database/data_gate.h"
#include "database/data_elements/data_item.h"

#include "session/permission_manager.h"

#include "data_controller.h"
#include "api/api_controller.h"
#include "session/permission_manager.h"

#include "stem.h"

Stem::Stem()
{
    logSplash();
    m_dataController = std::make_shared<DataController>();
    m_permissionManager = std::make_shared<PermissionManager>(m_dataController);
    m_apiController = std::make_shared<Api::ApiController>();
    m_apiController->setPermissionManager(m_permissionManager);
    m_apiController->setDataController(m_dataController);
}

Stem::~Stem()
{
}

int Stem::run()
{
    // FIXME: Убрать пример применения:
    // auto dg = Database::DataGate();
    // const auto a1 = dg.getElementsIds(&Database::DataItem::idsByParentId, 1);
    // const auto a2 = dg.getElementsIds(&Database::DataItem::idsByStateId, 132);
    // const auto a3 = dg.getElementsIds(&Database::DataItem::idsByUserState, "asdf", 132);
    m_apiController->run();
    return EXIT_SUCCESS;
}

void Stem::logSplash() const
{
    LOG_INFO << "Запуск системы";
}
